package com.csiec.clock.fragment.main;

import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.csiec.clock.R;
import com.csiec.clock.databinding.MineFragmentBinding;
import com.csiec.clock.view.model.MineViewModel;

public class MineFragment extends Fragment {

    private MineViewModel mViewModel;
    private MineFragmentBinding binding;

    public static MineFragment newInstance() {
        return new MineFragment();
    }

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        if(mViewModel == null){
            mViewModel = new MineViewModel();
        }
        binding = DataBindingUtil.inflate(inflater, R.layout.mine_fragment, container, false);
        return binding.getRoot();
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mViewModel = new ViewModelProvider(this).get(MineViewModel.class);
        mViewModel.init(requireActivity(),binding);
        binding.setMineViewModel(mViewModel);
        binding.setLifecycleOwner(this);
    }

}